package com.example.vo.Fragment

import android.content.DialogInterface
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.example.vo.Controller.RejectClick
import com.example.vo.Data.DB
import com.example.vo.R
import com.example.vo.TestActivity
import com.example.vo.Transform.DepthPageTransformer

class MainFragment : Fragment() {
    private var alertDialog1: AlertDialog? = null
    private var lastClickTime = 0L
    private val FAST_TIME = 1000
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val context = this.requireContext()
        val view = inflater.inflate(R.layout.fragment_main, container, false)
        val test_chang_t: TextView = view.findViewById(R.id.test_chang_t)
        val test_chang_n: TextView = view.findViewById(R.id.test_chang_n)
        val test_no_choose: TextView = view.findViewById(R.id.test_no_choose)
        val test_t: TextView = view.findViewById(R.id.test_t)
        val test_n: TextView = view.findViewById(R.id.test_n)
        val test_start: TextView = view.findViewById(R.id.test_start)

        var item = "小学"
        var num = "5"
        var maxnum = "5"
        val rightnum = "0"
        val onum = "0"
        val confirm = "0"
        test_t.text = "当前题库:" + item
        test_n.text = "当前词数:" + num
        test_start.setBackgroundColor(Color.parseColor("#5990D8"))
        test_chang_t.setBackgroundColor(Color.parseColor("#B0C4DE"))
        test_chang_n.setBackgroundColor(Color.parseColor("#B0C4DE"))
        test_no_choose.setBackgroundColor(Color.parseColor("#5990D8"))
        test_chang_t.setOnClickListener {
            val items = arrayOf("小学", "初中", "高中", "大学四级", "大学六级", "考研")
            val alertDialog = AlertDialog.Builder(context)
            alertDialog.setTitle("请选择")
            alertDialog.setSingleChoiceItems(
                items,
                0,
                object : DialogInterface.OnClickListener {
                    override fun onClick(dialog: DialogInterface, which: Int) {
                        item = items[which]
                        test_t.text = "当前题库:" + item
                        dialog.dismiss()
                    }
                })
            alertDialog1 = alertDialog.create()
            alertDialog1!!.show()
        }
        test_chang_n.setOnClickListener {
            val nums = arrayOf("5", "30", "50")
            val alertDialog = AlertDialog.Builder(context)
            alertDialog.setTitle("请选择")
            alertDialog.setSingleChoiceItems(
                nums,
                0,
                object : DialogInterface.OnClickListener {
                    override fun onClick(dialog: DialogInterface, which: Int) {
                        num = nums[which]
                        maxnum = num
                        test_n.text = "当前词数:" + num
                        dialog.dismiss()
                    }
                })
            alertDialog1 = alertDialog.create()
            alertDialog1!!.show()
        }

        test_start.setOnClickListener {
            if (System.currentTimeMillis() - lastClickTime >= FAST_TIME) {
                val intent = Intent(context, TestActivity::class.java).apply {
                    putExtra("item", item)
                    putExtra("num", num)
                    putExtra("maxnum", maxnum)
                    putExtra("rightnum", rightnum)
                    putExtra("onum", onum)
                    putExtra("confirm",confirm)
                }
                startActivity(intent)//防止多次点击
            }
        }

        test_no_choose.setOnClickListener {
            val item_ = "考研"
            val num_ = "30"
            val maxnum_ = "30"
            val rightnum_ = "0"
            val onum_ = "0"
            val confirm_ = "1"
            if (System.currentTimeMillis() - lastClickTime >= FAST_TIME) {
                val intent = Intent(context, TestActivity::class.java).apply {
                    putExtra("item", item_)
                    putExtra("num", num_)
                    putExtra("maxnum", maxnum_)
                    putExtra("rightnum", rightnum_)
                    putExtra("onum", onum_)
                    putExtra("confirm",confirm_)
                }
                startActivity(intent)//防止多次点击
            }
        }
        return view
    }
}